//
//  ChangePasswordViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/3/8.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ChangePasswordViewController.h"

@interface ChangePasswordViewController ()
@property (strong, nonatomic) IBOutlet UIView *navVew;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UITextField *oldPasswordField;
@property (strong, nonatomic) IBOutlet UITextField *nePasswordField;
@property (strong, nonatomic) IBOutlet UITextField *reNePasswordField;
@property (strong, nonatomic) IBOutlet UIButton *sureChangeButton;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navVew];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 504.5), YES);
    _sureChangeButton.layer.masksToBounds = YES;
    _sureChangeButton.layer.cornerRadius = 20*VerticalRatio();
 
    [_oldPasswordField setValue:[UIColor colorWithWhite:0.455 alpha:1.000]
               forKeyPath:@"_placeholderLabel.textColor"];
    [_nePasswordField setValue:[UIColor colorWithWhite:0.455 alpha:1.000]
                     forKeyPath:@"_placeholderLabel.textColor"];
    [_reNePasswordField setValue:[UIColor colorWithWhite:0.455 alpha:1.000]
                     forKeyPath:@"_placeholderLabel.textColor"];

    
}

- (IBAction)bakc:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

- (IBAction)sureChangeHandel:(id)sender {
    
    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
    if ([Common dataIsNULL:_oldPasswordField.text]) {
        [CWHUDTips showLoadingTips:_oldPasswordField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_nePasswordField.text]) {
        [CWHUDTips showLoadingTips:_nePasswordField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_reNePasswordField.text]) {
        [CWHUDTips showLoadingTips:_reNePasswordField.placeholder];
        return;
    }
    
    if (![_reNePasswordField.text isEqualToString:_nePasswordField.text]) {
        [CWHUDTips showLoadingTips:@"两次输入不一致"];
        return;
    }
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common shaEncrypt:_oldPasswordField.text] forKey:@"oldPwd"];
    [dic setObject:[Common shaEncrypt:_nePasswordField.text] forKey:@"newPwd"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_updateModifyPassword withHttpType:@"POST" withTag:SX_SX_updateModifyPassword];
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==SX_SX_updateModifyPassword) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
         [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
